package com.changgou.seckill.mq;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class QueueConfig {
    //创建queuel延时队列，会过期，过期后将数据发给Queue2
    @Bean
    public Queue orderDelayMessage() {
        return QueueBuilder
                .durable("seckillDelayQueue")
                .withArgument("x-dead-letter-exchange", "seckillExchange") ///死信队列数据绑定到其他交换机中,过期之后，进入死性队列，死信队列，绑定交换机
                .withArgument("x-dead-letter-routing-key", "seckillQueue")
                .build();
    }

    @Bean
    public Queue seckillQueue() {
        return new Queue("seckillQueue",true);
    }

    //创建死信交换机
    @Bean
    public Exchange seckillExchange() {
        return new DirectExchange("seckillExchange");
    }

    //队列Queue2绑定Exchange
    @Bean
    public Binding orderListenerBinding(Queue seckillQueue, Exchange seckillExchange) {
        return BindingBuilder.bind(seckillQueue).to(seckillExchange).with("seckillQueue").noargs();
    }
}
